package com.pb.b2b.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.NoneScoped;
import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

@NoneScoped
public class BaseDataModel<E> extends ListDataModel<E> implements SelectableDataModel<E>, Serializable {

	private static final long serialVersionUID = 1L;

	public BaseDataModel(List<E> data) {
		super(data);
	}

	@Override
	public Object getRowKey(E object) {
		return null;
	}

	@Override
	public E getRowData(String arg0) {
		return null;
	}

	public void setSelectedDataFirstRow(E selectedData) {
		if (selectedData != null) {
			List<E> list = new ArrayList<E>();
			list.add(selectedData);
			for (E data : this) {
				if (!data.equals(selectedData))
					list.add(data);
			}
			this.setWrappedData(list);
		}
	}

	// public boolean isEmpty() {
	// return this.getRowCount() <= 0;
	// }
}
